/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.customer.credit.details.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.customer.credit.details.entity.TcustomerCreditDetails;
import com.jeesite.modules.zx.customer.credit.details.service.TcustomerCreditDetailsService;

/**
 * 客户学分明细Controller
 * @author zpp
 * @version 2020-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/customer/credit/details/tcustomerCreditDetails")
public class TcustomerCreditDetailsController extends BaseController {

	@Autowired
	private TcustomerCreditDetailsService tcustomerCreditDetailsService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcustomerCreditDetails get(String id, boolean isNewRecord) {
		return tcustomerCreditDetailsService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:customer:credit:details:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcustomerCreditDetails tcustomerCreditDetails, Model model) {
		model.addAttribute("tcustomerCreditDetails", tcustomerCreditDetails);
		return "modules/zx/customer/credit/details/tcustomerCreditDetailsList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:customer:credit:details:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcustomerCreditDetails> listData(TcustomerCreditDetails tcustomerCreditDetails, HttpServletRequest request, HttpServletResponse response) {
		tcustomerCreditDetails.setPage(new Page<>(request, response));
		Page<TcustomerCreditDetails> page = tcustomerCreditDetailsService.findPage(tcustomerCreditDetails);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:customer:credit:details:view")
	@RequestMapping(value = "form")
	public String form(TcustomerCreditDetails tcustomerCreditDetails, Model model) {
		model.addAttribute("tcustomerCreditDetails", tcustomerCreditDetails);
		return "modules/zx/customer/credit/details/tcustomerCreditDetailsForm";
	}

	/**
	 * 保存客户学分明细
	 */
	@RequiresPermissions("zx:customer:credit:details:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcustomerCreditDetails tcustomerCreditDetails) {
		tcustomerCreditDetailsService.save(tcustomerCreditDetails);
		return renderResult(Global.TRUE, text("保存客户学分明细成功！"));
	}
	
	/**
	 * 停用客户学分明细
	 */
	@RequiresPermissions("zx:customer:credit:details:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcustomerCreditDetails tcustomerCreditDetails) {
		tcustomerCreditDetails.setStatus(TcustomerCreditDetails.STATUS_DISABLE);
		tcustomerCreditDetailsService.updateStatus(tcustomerCreditDetails);
		return renderResult(Global.TRUE, text("停用客户学分明细成功"));
	}
	
	/**
	 * 启用客户学分明细
	 */
	@RequiresPermissions("zx:customer:credit:details:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcustomerCreditDetails tcustomerCreditDetails) {
		tcustomerCreditDetails.setStatus(TcustomerCreditDetails.STATUS_NORMAL);
		tcustomerCreditDetailsService.updateStatus(tcustomerCreditDetails);
		return renderResult(Global.TRUE, text("启用客户学分明细成功"));
	}
	
	/**
	 * 删除客户学分明细
	 */
	@RequiresPermissions("zx:customer:credit:details:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcustomerCreditDetails tcustomerCreditDetails) {
		tcustomerCreditDetailsService.delete(tcustomerCreditDetails);
		return renderResult(Global.TRUE, text("删除客户学分明细成功！"));
	}
	
}